
#define BITS_PER_MESSAGE 12    
#define B_1 1000              //1.2 milliseconds        
#define B_0 400                //0.6 milliseconds       
#define START_BIT 2000   //making it a little shorter than the actual 2400   
#define IR_PIN 7
#define LED_PIN 9
#define LED_STEP 10
 
//find the threshold time b/w the two pulse sizes
#define BIT_THRESH B_0+((B_1-B_0)/2)
int ledValue=0;
void setup() {
  pinMode(IR_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  delay(1000);
  Serial.begin(9600);
  Serial.println("Ready...");
}

void doSomething(unsigned int code)
{
  Serial.println(code);
   
  //analogWrite(LED_PIN, ledValue);
  
}
void loop() {
  //int where we are storing code, must start at 0
  unsigned int code = 0x00;
 
   
 
  //block until start pulse
   while (pulseIn(IR_PIN, LOW) < START_BIT) {}
   analogWrite(LED_PIN, 255);
  //read in next 12 bits shifting and masking them into the unsigned int 'code'
  //remeber boolean is basically 0 [false] or 1 [true]
  for (byte i = 0; i < BITS_PER_MESSAGE; i++) {
      code |= (pulseIn(IR_PIN, LOW) > BIT_THRESH) << i;  
  }
 
 // Serial.println(code);
  doSomething(code);
  //delay(200);
  analogWrite(LED_PIN, 0);
}
